package cn._51doit.flink.day02;

import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.sink.SinkFunction;

public class MyPrintSink1 {

    public static void main(String[] args) throws Exception {

        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        DataStreamSource<String> lines = env.socketTextStream("localhost", 8888);

        //lines.print();
        lines.addSink(new PrintSink1());

        env.execute();


    }

    /**
     * 泛型代表进入到Sink中的数据的类型
     */
    private static class PrintSink1 implements SinkFunction<String> {


        /**
         * 该方法就是决定Sink如何将数据输出（下沉）
         * @param value 前面的算子发送给sink的数据
         * @param context
         * @throws Exception
         */
        @Override
        public void invoke(String value, Context context) throws Exception {
            System.out.println(value);
        }
    }
}
